using DiagnosticSourceDemo.Host;
using System.Diagnostics;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHttpContextAccessor();

DiagnosticListener.AllListeners.Subscribe(new ExampleDiagnosticObserver(builder.Services));
DiagnosticListener.AllListeners.Subscribe(new MyObserver<DiagnosticListener>(listener =>
{
    if (listener.Name == "HttpHandlerDiagnosticListener")
    {
        listener.SubscribeWithAdapter(new MyDiagnosticListener(builder.Services));
    }
}));

var app = builder.Build();
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();